﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GDD2_Game3
{
    class GameObject
    {
        //attributes
		protected FloatBox box;
        protected Vector2 direction;
        protected float rotation;

		public FloatBox Box { get { return box; } }
		public float Rotation { get { return rotation; } }

        //Constructor
        public GameObject(float x, float y, float width, float height)
        {
            box = new FloatBox(x, y, width, height);
            direction = new Vector2(1, 0);
            rotation = 0.0f;
        }

        public bool colliding(GameObject itemToCheck)
        {
            if (box.intersects(itemToCheck.box))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

		// returns the new direction vector after a bounce given an inital vector and the intersection info of the collision
		protected Vector2 applyBounce(Vector2 initDirection, FloatBox.IntersectionInformation intersectInfo)
		{
			return initDirection * bounceUnit(intersectInfo); // NOT scalar, dot, or cross product, but corresponding component multiplication (i.e. (1, 2) * (3, 4) = (3, 8))
		}

		// returns:
		// (-1, 1) if bounces on the left or right, but not top or bottom
		// (1, -1) if bounces on the top or bottom, but not left or right
		// (-1, -1) if bounces from both top or bottom and left or right (AKA, bounces exactly on a corner)
		// (1, 1) if no collision
		protected Vector2 bounceUnit(FloatBox.IntersectionInformation intersectInfo)
		{
			return new Vector2((intersectInfo.OtherToLeft || intersectInfo.OtherToRight) ? -1 : 1, (intersectInfo.OtherAbove || intersectInfo.OtherBelow) ? -1 : 1);
		}
    }
}